﻿Imports System.Data.OleDb

Public Class ChiTietHoaDonDAO

    Public Function GetTable() As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "select * from CHITIETHOADON"
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)

        cn.Close()
        Return dt
    End Function

    Public Function Insert(ByVal tmp As ChiTietHoaDonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into CHITIETHOADON (MaHD, MaMon, SoLuong, ThanhTien) values (@MaHD, @MaMon, @SoLuong, @ThanhTien)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4 As OleDbParameter
        para1 = New OleDbParameter("@MaHD", tmp.MaHD)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@MaMon", tmp.MaMon)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@SoLuong", tmp.SoLuong)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@ThanhTien", tmp.ThanhTien)
        cmd.Parameters.Add(para4)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As ChiTietHoaDonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update CHITIETHOADON set SoLuong=@SoLuong, ThanhTien=@ThanhTien where MaHD=@MaHD and MaMon=@MaMon"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4 As OleDbParameter
        para1 = New OleDbParameter("@SoLuong", tmp.SoLuong)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@ThanhTien", tmp.ThanhTien)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@MaHD", tmp.MaHD)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@MaMon", tmp.MaMon)
        cmd.Parameters.Add(para4)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As ChiTietHoaDonDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from CHITIETHOADON where MaHD=@MaHD and MaMon=@MaMon"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2 As OleDbParameter
        para1 = New OleDbParameter("@MaHD", tmp.MaHD)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@MaMon", tmp.MaMon)
        cmd.Parameters.Add(para2)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

End Class
